package com.cyan.teamquestionnaire.mappers;

import com.cyan.teamquestionnaire.entity.SecurityQuestion;
import org.apache.ibatis.annotations.*;

@Mapper
public interface SecurityQuestionMapper {

    // 限定每个账号只有一个密保问题，这样查出来的结果只有一个对象
    @Results({
            @Result(column = "user_name", property = "userName")
    })
    @Select("select * from security_question where user_name = #{userName} limit 1")
    SecurityQuestion getQuestionByName(String userName);

    // 创建一个密保问题
    @Insert("insert into security_question(user_name, question, answer) values(#{userName}, #{question}, #{answer})")
    void createSecurityQuestion(SecurityQuestion securityQuestion);

    // 修改密保问题
    @Update("update security_question set question = #{question}, answer = #{answer} where user_name = #{userName}")
    void modifySecurityQuestion(SecurityQuestion securityQuestion);

    // 删除密保问题（删除用户时调用）
    @Delete("delete from security_question where user_name = #{userName}")
    void deleteSecurityQuestion(String userName);
}
